import PlatformAdapter from "./BaseAdapter";
import WechatAdapter from "./WechatAdapter";
import KsAdapter from "./KsAdapter";
import AlipayAdapter from "./AlipayAdapter";
import DefaultAdapter from "./DefaultAdapter";

export default class CrossPlatformAdapter {

    private static currentAdapter: PlatformAdapter;


    private static get onKS() {
        //@ts-ignore
        let res = typeof KSGameGlobal !== 'undefined' && cc.sys.platform === cc.sys.WECHAT_GAME
        return res;
    }

    public static get adapter(): PlatformAdapter {
        return this.currentAdapter;
    };

    public static initPlatformAdapter() {
        this.currentAdapter = new DefaultAdapter();
        if (this.onKS) {
            this.currentAdapter = new KsAdapter();
        }
    }

    static showToast(msg: string) {
        console.log("showToast", msg);
        this.currentAdapter.showToast(msg);
    }

    static showAlert(msg: string) {
        console.log("showAlert", msg);
        this.currentAdapter.showAlert(msg);
    }

    static showLoading(msg: string) {
        console.log("showLoading", msg);
        this.currentAdapter.showLoading(msg);
    }

    static hideLoading() {
        this.currentAdapter.hideLoading();
    }

}

CrossPlatformAdapter.initPlatformAdapter();